<div class="row row-cards row-deck">
  <div class="col-2">
    <div class="card">
      <div class="card-body">
        <div class="form-group">
          <label class="form-label">订单处理</label>
          <div class="form-control-plaintext">
            <% OrderItem.states.keys.each do |state| %>
              <% if state == 'after_sale' || state == 'agree' || state == 'disagree' %>
              <div><%= link_to "#{I18n.t("order_item.state.#{state.downcase}")}", request.parameters.merge({state: state}) %></div>
              <% end %>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-10">
    <div class="card">
      <div class="card-header">
        <a href="<%= request.parameters.merge({between: "today"}) %>" style="margin-right: 20px;" class="btn btn-pill btn-warning">今天</a>
        <a href="<%= request.parameters.merge({between: "by_week"}) %>" style="margin-right: 20px;" class="btn btn-pill btn-warning">本周</a>
        <a href="<%= request.parameters.merge({between: "by_month"}) %>" style="margin-right: 20px;" class="btn btn-pill btn-warning">本月</a>
      </div>
      <table class="table table-hover table-outline table-vcenter text-nowrap card-table">
        <thead>
          <tr>
            <th>订单编号</th>
            <th>总价</th>
            <th>数量</th>
            <th>下单用户</th>
            <th>下单电话</th>
            <th>状态</th>
            <th>退款类型</th>
            <th>申请时间</th>
            <th class="text-center">
            </th>
          </tr>
        </thead>
        <tbody>
          <% @order_items.each do |order_item| %>
            <tr>
              <td>
                <div><%= order_item.order.trade_no %></div>
                <div class="small text-muted">
                  <%= formattime(order_item.order.created_at, unit: "hour") %>
                </div>
              </td>
              <td>
                <div><%= order_item.fee * order_item.quantity %></div>
              </td>
              <td>
                <div><%= order_item.quantity %></div>
              </td>
              <td>
                <div><%= order_item.order.user.blank? ? "订单所属用户已删除" : order_item.order.user.nickname  %></div>
              </td>
              <td>
                <div><%= order_item.order.user.blank? ? "订单所属用户已删除" : order_item.order.user.phone %></div>
              </td>
              <td>
                <div><%= i18n_enum order_item, :state %></div>
              </td>
              <td>
                <div>
                  <% if not order_item.after_sale_type.blank? %>
                    <span class="status-icon bg-success"></span>
                    <%= i18n_enum order_item, :after_sale_type %>
                  <% end %>
                </div>
              </td>
              <td>
                <div><%= formattime(order_item.refund_at, unit: "hour") %></div>
              </td>
              <td class="text-center">
                <div class="item-action dropdown">
                  <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
                  <div class="dropdown-menu dropdown-menu-right">
                    <a href="<%= shop_order_path(order_item.order) %>" class="dropdown-item"><i class="dropdown-icon fe fe-tag"></i> 查看关联订单 </a>
                    <% if order_item.after_sale? || order_item.agree? || order_item.disagree? %>
                      <a href="<%= edit_shop_order_item_path(order_item) %>" class="dropdown-item"><i class="dropdown-icon fe fe-tag"></i> 审批 </a>
                      <% if order_item.agree? %>
                        <%= link_to refund_shop_order_item_path(order_item), class: "dropdown-item", method: :post do %>
                          <i class="dropdown-icon fe fe-tag"></i> 退款
                        <% end %>
                      <% end %>
                    <% end %>
                  </div>
                </div>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
      <div class="card-footer">
        <%= paginate @order_items %>
      </div>
    </div>
  </div>
</div>